﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jiaju.Models.DAL;
using jiaju.Models.DBModel;
using jiaju.Models;
namespace jiaju.Controllers
{
    public class NewsController : Controller
    {
        // GET: News
        public ActionResult Index(String id)
        {
            //新闻资讯
            List<NewsType> news = NewsTypeService.getAllType();
            ViewBag.A = news;
            if (string.IsNullOrEmpty(id))
            {
                ViewBag.B = 0;
            }
            else
            {
                ViewBag.B = id;
            }
            return View();
        }

        public ActionResult DelPage(int page, int limit, int id)
        {
            if (id == 0)
            {
                //获取分页商品
                List<News> newsList = NewsService.getNewsPage(page, limit);
                //获取共有多少条
                string sql = "select COUNT (*)from dbo.news";
                int count = (int)DBHelp.ExcuteScalar(sql);
                return Json(new
                {
                    success = true,
                    count = count,
                    data = newsList
                });
            }
            else
            {
                //获取分页商品
                List<News> newsList = NewsService.getNewsPage2(page, limit, id);
                //获取共有多少条
                string sql = "select COUNT (*)from dbo.news where TypeId=" + id;
                int count = (int)DBHelp.ExcuteScalar(sql);
                return Json(new
                {
                    success = true,
                    count = count,
                    data = newsList
                });
            }
        }
    }
}